home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / clipper / ks94an.zip / MULT.HDR < prev    next >
Text File  |  1994-04-25  |  3KB  |  108 lines

  1. /******************************************************************************
  2.                  The Klipper Library, for CA-Clipper 5.x
  3.         Copyright (c), 1994, Wallace Information Systems Engineering
  4.  
  5. FUNCTION:
  6.  
  7. _Mult( cVal1, cVal2 ) --> cProduct
  8.  
  9. PARAMETERS:
  10.  
  11. cVar1 : Multiplicand
  12. cVar2 : Multiplier
  13.  
  14. SHORT:
  15.  
  16. Perform multiplication to 64,000 digits (I swear, it's the truth!, kinda)
  17.  
  18. DESCRIPTION:
  19.  
  20. _Mult() performs multiplication on POSITIVE whole numbers represented
  21. as strings.  The benefit of this is that you may multiply numbers
  22. of astronomical proportions: 65,535 total digits!  Thus, the two
  23. largest numbers that could be multiplied (give or take - probably take -
  24. a digit or two) would be:
  25.  
  26. _Mult( Replicate('9',32768), Replicate('9',32768) )
  27.  
  28. I'll spare you the result of this operation!  If you printed it, it would
  29. span 11 pages in compressed print or stretch about 420 feet if printed all
  30. on one line (including commas)!
  31.  
  32. A product of two numbers will never exceed twice the number of the number
  33. of digits in the multiplicand and the multiplier. (that is, xx*yy will
  34. never exceed 4 significant digits, xxx*yyy will never exceed 6
  35. significant digits, etc.)  For that reason, 64K is the maximum number
  36. of digits between the two numbers.  The following would work:
  37.  
  38. _Mult( Replicate('9',60000), Replicate('9',2000) )
  39.  
  40. because the product will be no greater than 62000 digits long.
  41.  
  42.  
  43. This would NOT work:
  44.  
  45. _Mult( Replicate('9',60000), Replicate('9',9000) )
  46.  
  47. because the resulting string will exceed the capacity of Clipper's string
  48. data type.  It couldn't allocate a string big enough to hold the
  49. resulting number string!
  50.  
  51. The product is always returned as a string for obvious reasons.
  52.  
  53. If you embed a space or other non-digit character in a number string, then
  54. you're just dumb and outta luck!  It will work, but you will get unreliable
  55. and incorrect results.
  56.  
  57. NOTE:
  58.  
  59.  
  60.  
  61. EXAMPLE:
  62.  
  63. cStr = _Mult('123',321')
  64.  
  65. ? cStr = '39483' // .t.
  66.  
  67. ? _Mult('1234567890123456789','545') = '67283950011728395005' // .t.
  68.  
  69.  
  70. Clipper Numeric and _Mult() multiplications:
  71.  
  72.     12345678901234567890
  73.                      x 1
  74.     --------------------
  75.     12345678901234570000   Numeric
  76.     12345678901234567890   _Mult()
  77.  
  78.  
  79.     12345678901234567890
  80.                      x 8
  81.     --------------------
  82.     98765431209876540000   Numeric
  83.     98765431209876543120   _Mult()
  84.  
  85.  
  86.     12345678901234567890
  87.                      x 9
  88.     --------------------
  89.     ********************   Numeric
  90.    111111110111111111010   _Mult()
  91.  
  92.  
  93. Why not?  What the heck?  How about:
  94.  
  95.  
  96.                       1234567890123456789
  97.                     x 1234567890123456789
  98.                     ---------------------
  99.                      * Are You kidding? *   Numeric
  100.     1524157875323883675019051998750190521   _Mult()
  101.  
  102.  
  103. Yes, now YOU too can work for the congressional budget office and explain
  104. Bill Clinton's tax policies - They've been using this function for a year
  105. now, really.  I swear it's the truth!  Would I lie?
  106.  
  107. ******************************************************************************/
  108.